package com.corner.system.utils;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 订单号工具类
 *
 * @author qy
 * @since 1.0
 */
public class OrderNoUtils {


    private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    private static final Random RANDOM = new SecureRandom();
    /**
     * 获取订单编号
     * @return
     */
    public static String getOrderNo() {
        return "ORDER_" + getNo();
    }

    public static String getPayOrderNo() {
        return "PORDER" + getNo();
    }

    /**
     * 获取退款单编号
     * @return
     */
    public static String getRefundNo() {
        return "REFUND_" + getNo();
    }

    /**
     * 获取商家转账到零钱单编号
     * @return
     */
    public static String getBatchNo() {
        return "BATCH" + getNo();
    }
    /**
     * 获取商家转账到零钱单编号
     * @return
     */
    public static String getBatchDetailNo() {
        return "BATCHDT" + getNo();
    }

    /**
     * 获取编号
     * @return
     */
    public static String getNo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = sdf.format(new Date());
        Random random = new Random();
/*        String result = "";
        for (int i = 0; i < 3; i++) {
            result += random.nextInt(10);
        }*/
        String nonceStr = generateNonceStr(8);
        return newDate + nonceStr;//30位
    }


    //随机字符串
    public static String generateNonceStr(int len) {
        char[] nonceChars = new char[len];
        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }

    public static void main(String[] args) {
        String s = "B_DETAIL" + getNo();
        System.out.println(s);
        System.out.println(s.length());
    }



}
